package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.PtfInterfaceField;
import com.ruoyi.system.service.IPtfInterfaceFieldService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 字段管理Controller
 * 
 * @author ruoyi
 * @date 2022-11-20
 */
@RestController
@RequestMapping("/interfaceField")
public class PtfInterfaceFieldController extends BaseController
{
    @Autowired
    private IPtfInterfaceFieldService ptfInterfaceFieldService;

    /**
     * 查询字段管理列表
     */
    @RequiresPermissions("system:interfaceField:list")
    @GetMapping("/list")
    public TableDataInfo list(PtfInterfaceField ptfInterfaceField)
    {
        startPage();
        List<PtfInterfaceField> list = ptfInterfaceFieldService.selectPtfInterfaceFieldList(ptfInterfaceField);
        return getDataTable(list);
    }

    /**
     * 导出字段管理列表
     */
    @RequiresPermissions("system:interfaceField:export")
    @Log(title = "字段管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PtfInterfaceField ptfInterfaceField)
    {
        List<PtfInterfaceField> list = ptfInterfaceFieldService.selectPtfInterfaceFieldList(ptfInterfaceField);
        ExcelUtil<PtfInterfaceField> util = new ExcelUtil<PtfInterfaceField>(PtfInterfaceField.class);
        util.exportExcel(response, list, "字段管理数据");
    }

    /**
     * 获取字段管理详细信息
     */
    @RequiresPermissions("system:interfaceField:query")
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") Long fieldId)
    {
        return AjaxResult.success(ptfInterfaceFieldService.selectPtfInterfaceFieldByFieldId(fieldId));
    }

    /**
     * 新增字段管理
     */
    @RequiresPermissions("system:interfaceField:add")
    @Log(title = "字段管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtfInterfaceField ptfInterfaceField)
    {
        return toAjax(ptfInterfaceFieldService.insertPtfInterfaceField(ptfInterfaceField));
    }

    /**
     * 修改字段管理
     */
    @RequiresPermissions("system:interfaceField:edit")
    @Log(title = "字段管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtfInterfaceField ptfInterfaceField)
    {
        return toAjax(ptfInterfaceFieldService.updatePtfInterfaceField(ptfInterfaceField));
    }

    /**
     * 删除字段管理
     */
    @RequiresPermissions("system:interfaceField:remove")
    @Log(title = "字段管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable Long[] fieldIds)
    {
        return toAjax(ptfInterfaceFieldService.deletePtfInterfaceFieldByFieldIds(fieldIds));
    }
}
